<!-- 用户头像表单 -->
<template>
  <div>
    <el-form ref="form" :model="ids" label-width="80px">
      <el-form-item label="头像列表">
        <el-radio-group v-model="ids.picId" v-for="l in list" :key="l.picId">
          <el-radio :label="l.picId">
            <div style="height: 200px; width: 200px">
              <img
                :src="l.picLink"
                alt="用户头像"
                style="width: 80%; height: 80%"
              />
            </div>
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="updateUserImg">确认</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "userimgform",
  data() {
    return {
      // 图片列表
      list: [],
      //   修改头像图片，请求参数
      ids: { userId: localStorage.getItem("USERID") },
    };
  },
  methods: {
    userImgList() {
      this.$api.picturesApi.userImgList().then((res) => {
        this.list = res.data.data;
      });
    },
    updateUserImg() {
      this.$api.usersApi
        .updateUserImg({ picId: this.ids.picId, userId: this.ids.userId })
        .then((res) => {
          if (res.data.code == 1) {
            this.$notify({
              title: "成功",
              message: "头像修改成功！",
              type: "success",
            });
          } else {
            this.$notify.error({
              title: "错误",
              message: "头像修改失败！",
            });
          }
        });
    },
  },
  mounted() {
    this.userImgList();
  },
};
</script>

<style scoped></style>
